Imports System.Windows.Forms

Public Class dlgDiceForumla

    Private _dice As New DiceRoll

    Public Property Dice() As DiceRoll
        Get
            Return _dice
        End Get
        Set(ByVal value As DiceRoll)
            _dice = value
            UpdateDisplay()
        End Set
    End Property

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub numDice_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numDice.ValueChanged
        If _dice.NumberOfDice <> numDice.Value Then
            _dice.NumberOfDice = CInt(numDice.Value)
            UpdateDisplay()
        End If
    End Sub

    Private Sub numSides_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numSides.ValueChanged
        If _dice.NumberOfSidesPerDice <> numSides.Value Then
            _dice.NumberOfSidesPerDice = CInt(numSides.Value)
            UpdateDisplay()
        End If
    End Sub

    Private Sub numModifier_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numModifier.ValueChanged
        If _dice.Modifier <> numModifier.Value Then
            _dice.Modifier = CInt(numModifier.Value)
            UpdateDisplay()
        End If
    End Sub

    Private Sub UpdateDisplay()
        numDice.Value = _dice.NumberOfDice
        numSides.Value = _dice.NumberOfSidesPerDice
        numModifier.Value = _dice.Modifier
        lblRange.Text = "Ranges " & _dice.Range
    End Sub
End Class
